# 简化版Dockerfile - 使用Ubuntu基础镜像避免Alpine问题
FROM node:20-slim AS builder

# 设置工作目录
WORKDIR /app

# 设置npm镜像源
RUN npm config set registry https://registry.npmmirror.com

# 复制package.json和package-lock.json
COPY package*.json ./

# 清理npm缓存
RUN npm cache clean --force

# 删除package-lock.json避免可选依赖问题
RUN rm -f package-lock.json

# 重新安装依赖
RUN npm install --timeout=300000

# 复制源代码
COPY . .

# 只进行构建，跳过类型检查
RUN npm run build-only

# 生产阶段 - 使用nginx提供静态文件服务
FROM nginx:alpine AS production

# 复制构建好的文件到nginx目录
COPY --from=builder /app/dist /usr/share/nginx/html

# 复制nginx配置文件
COPY nginx.conf /etc/nginx/nginx.conf

# 暴露端口
EXPOSE 80

# 启动nginx
CMD ["nginx", "-g", "daemon off;"]
